#include <iostream>
using namespace std;

/*无参构造函数想要调用有参构造函数必须使用初始化列表*/
class Person
{
public:
    Person()
    {
        cout << "父类无参构造\n";
    }

public:
    int m_age;
};
class Student : public Person
{
public:
    Student()
    {
        cout << "子类无参构造\n";
    }

public:
    int m_no;
};
int main()
{
/*子类构造函数默认会调用父类的无参构造函数*/
#if 0
    Student *p = new Student();
    p->m_age = 30;
    p->m_no = 10;
    cout << p->m_age << endl;
    cout << p->m_no << endl;
#endif
#if 0
    /*父类指针指向子类是允许的*/
    Person *per = new Student();
    per->m_age = 60;
    cout << per->m_age << endl;
    return 0;
#endif
    /*子类指针指向父类对象不允许使用*/
    Student *pStu = (Student *)new Person();
    pStu->m_age = 30;

    /*访问m_no的时候会踩内存*/
    pStu->m_no = 10;
    cout << pStu->m_age << endl;
    cout << pStu->m_no << endl;
}